<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

class AdhesionModel extends JLModelBase {

    /**
     * Funcion que retorna Adhesion
     * @Retorna bool
     */
    public function getAdhesionById($id) {
        $_true = null;

        $sql = "SELECT 
              `int_id_adhesion`,
              `var_title_link`,
              `var_link_pdfword`,
              `int_id_sections_view`,
              `int_id_state`
            FROM 
              `tbl_adhesion` 
            WHERE `int_id_adhesion` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getDataArray();
            $_true = $_true[0];
        }

        return $_true;
    }

    /**
     * Funcion que retorna Adhesion
     * @Retorna bool
     */
    public function getAdhesionByIdSectionsView($id) {
        $_true = null;

        $sql = "SELECT 
              `int_id_adhesion`,
              `var_title_link`,
              `var_link_pdfword`,
              `int_id_sections_view`
            FROM 
              `tbl_adhesion` 
            WHERE `int_id_sections_view` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getDataArray();
        }

        return $_true;
    }

    /**
     * Inserta Adhesion
     * @Retorna bool
     */
    public function insertAdhesion($var_title_link, $var_link_pdfword, $int_id_sections_view, $int_id_state) {
        $_true = false;

        $sql = "INSERT INTO 
              `tbl_adhesion`
            (
              `var_title_link`,
              `var_link_pdfword`,
              `int_id_sections_view`,
              `int_id_state`
            ) 
            VALUE(
              " . $this->DB->Quote($var_title_link) . ",
              " . $this->DB->Quote($var_link_pdfword) . ",
              " . $this->DB->Quote($int_id_sections_view) . ",
              " . $this->DB->Quote($int_id_state) . "
            )";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Update Adhesion
     * @Retorna bool
     */
    public function updateAdhesion($id, $var_title_link, $var_link_pdfword, $int_id_sections_view, $int_id_state) {
        $_true = false;

        $sql = "UPDATE 
              `tbl_adhesion`  
            SET
              `var_title_link`   = " . $this->DB->Quote($var_title_link) . ",
              `var_link_pdfword` = " . $this->DB->Quote($var_link_pdfword) . ",
              `int_id_sections_view` = " . $this->DB->Quote($int_id_sections_view) . ",
              `int_id_state` = " . $this->DB->Quote($int_id_state) . " 
            WHERE 
              `int_id_adhesion` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Elimina usuario
     * @Retorna string
     */
    public function DeleteAdhesion($_id) {
        $sql = "DELETE FROM 
              `tbl_adhesion` 
            WHERE 
              `int_id_adhesion` = " . $this->DB->Quote($_id) . " AND `int_id_state` <> 1";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        } else {
            $_true = false;
        }

        return $_true;
    }

}